<template>
    <div id="MenuTags">
        <div class="arrow-left arrow">
            <el-icon>
                <arrow-left />
            </el-icon>
        </div>
        <div class="tags_wrap">
            <template v-for="item in tags" :key="item.path">
                <div class="tag_item no-select">
                    <router-link
                        :to="item.path"
                        class="linkWrap"
                        :class="{ current: route.path === item.path }"
                    >
                        <div class="dot"></div>
                        <span class="title">{{ item.name }}</span>
                    </router-link>
                    <el-icon
                        class="icon"
                        @click="handleClose(item.path)"
                        v-if="item.path !== '/welcome'"
                    >
                        <close />
                    </el-icon>
                </div>
            </template>
        </div>
        <div class="arrow-rgiht arrow">
            <el-icon>
                <arrow-right />
            </el-icon>
        </div>
        <el-dropdown
            class="close_dropDown"
            trigger="click"
            size="default"
            :show-timeout="0"
            :hide-timeout="0"
        >
            <div class="close arrow">
                <el-icon>
                    <circle-close />
                </el-icon>
            </div>
            <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item>关闭所有</el-dropdown-item>
                    <el-dropdown-item>关闭其他</el-dropdown-item>
                </el-dropdown-menu>
            </template>
        </el-dropdown>
    </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router';
import { useStore } from 'vuex';
const route = useRoute()
const router = useRouter()
const store = useStore()

const tags = store.state.tagList

// 组件创建完毕
store.commit('addTag', { name: route.meta.title, path: route.path })
// 处理关闭标签
function handleClose (path) {
    store.commit('removeTag', path)
    router.push('/')
}
</script>

<style lang='less'>
#MenuTags {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 35px;
    padding: 1px;
    box-shadow: inset 0 0 10px 1px rgba(0, 0, 0, 0.2);
    .arrow {
        background-color: var(--bgColor3);
        height: 100%;
        width: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
    }
    .tags_wrap {
        flex: 1;

        display: flex;
        align-items: center;
        height: 100%;

        padding: 0 10px;
        .tag_item {
            position: relative;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 5px;
            height: 80%;
            margin-right: 15px;
            border-radius: 3px;
            background-color: var(--bgColor3);
            cursor: pointer;

            .linkWrap {
                display: flex;
                align-items: center;
                .dot {
                    width: 10px;
                    height: 10px;
                    border-radius: 50%;
                    background-color: rgba(0, 0, 0, 0.4);
                    transition: all 0.5s ease;
                }
                .title {
                    font-size: 12px;
                    color: rgba(0, 0, 0, 0.5);
                    padding: 0 12px;
                }
            }

            .icon {
                border-radius: 50%;
                font-size: 12px;
                color: rgba(0, 0, 0, 0.4);
            }
            .current {
                .dot {
                    background-color: #5a9cf8;
                }
            }
        }
        .tag_item:hover {
            .dot {
                filter: brightness(80%);
            }
            .title,
            .icon {
                color: rgba(0, 0, 0, 0.6);
            }
        }
    }
    .close_dropDown {
        height: 100%;
        .close {
            margin-left: 1px;
            width: 30px;
            color: rgba(0, 0, 0, 0.4);
        }
    }
}
</style>
